/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vista;

import controlador.PagosComboControlador;
import java.awt.event.ItemEvent;
import java.sql.Array;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import static javax.swing.JOptionPane.showMessageDialog;
import javax.swing.table.DefaultTableModel;
import model.PagosCombo;

/**
 *
 * @author anex
 */
public class medioPagoForm extends javax.swing.JDialog{

    /**
     * Creates new form medioPago
     */
     
    public medioPagoForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        getMedioPago();
        
     
    }
    public medioPagoForm(){
      initComponents();
       getMedioPago();
    }
  
    
    
    private void  getMedioPago()
    {
      Vector<PagosCombo> pagoVector = new Vector<PagosCombo>();
       PagosCombo pagoModelo= null; 
       PagosComboControlador pagosBD = new PagosComboControlador();
      
     
        try (ResultSet rs2 = pagosBD.datos()) {
   
             while (rs2.next()) {
                   pagoModelo=new PagosCombo();
                   pagoModelo.setIdPago(rs2.getInt(1));
                   pagoModelo.setNombre(rs2.getString(2));
                   pagoVector.add(pagoModelo);
               }
             
             rs2.close();
             
                   
             }catch (Exception ex) {
                showMessageDialog(null,  ex, "Error", JOptionPane.WARNING_MESSAGE);
             }
        DefaultComboBoxModel md1 = new DefaultComboBoxModel(pagoVector);
        CBmedioPago.setModel(md1);
        
       
      /* Vector<PagosCombo> pagoVector = new Vector<PagosCombo>();
       PagosCombo pagoModelo= new PagosCombo();
       PagosComboControlador pagosBD = new PagosComboControlador();
       
     
        try (ResultSet rs2 = pagosBD.datos()) {
   
             while (rs2.next()) {
                 
                   pagoModelo.setNombre(rs2.getString(2));
                   pagoVector.add(pagoModelo);
               }
             
             rs2.close();
             
                   
             }catch (Exception ex) {
                showMessageDialog(null,  ex, "Error", JOptionPane.WARNING_MESSAGE);
             }
        DefaultComboBoxModel md1 = new DefaultComboBoxModel(pagoVector);
        CBmedioPago.setModel(md1);*/
       
          
        }
    


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        JTmedioPago = new javax.swing.JTable();
        CBmedioPago = new javax.swing.JComboBox();
        txtMonto = new javax.swing.JTextField();
        labelAñadir = new javax.swing.JLabel();
        txtPrueba = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        JTmedioPago.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Medio de Pago", "Descripcion", "Monto"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Double.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        JTmedioPago.setColumnSelectionAllowed(true);
        JTmedioPago.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                JTmedioPagoFocusLost(evt);
            }
        });
        jScrollPane1.setViewportView(JTmedioPago);
        JTmedioPago.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        CBmedioPago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "GS", "US", "TARJETA" }));
        CBmedioPago.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                CBmedioPagoItemStateChanged(evt);
            }
        });

        labelAñadir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/add.png"))); // NOI18N
        labelAñadir.setAutoscrolls(true);
        labelAñadir.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        labelAñadir.setIconTextGap(0);
        labelAñadir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                labelAñadirMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(96, 96, 96)
                        .addComponent(CBmedioPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(txtMonto, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelAñadir, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPrueba, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(CBmedioPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtMonto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(labelAñadir, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPrueba, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JTmedioPagoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_JTmedioPagoFocusLost

             
                if (JTmedioPago.isColumnSelected(0)){
                                             
                  
                                           
                
                }
    }//GEN-LAST:event_JTmedioPagoFocusLost

    private void labelAñadirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelAñadirMouseClicked
    
    }//GEN-LAST:event_labelAñadirMouseClicked

    private void CBmedioPagoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_CBmedioPagoItemStateChanged
        if(evt.getStateChange()== ItemEvent.SELECTED){
                PagosCombo pago = (PagosCombo) this.CBmedioPago.getSelectedItem();
                 txtPrueba.setText("CI: "+ pago.getIdPago());
        }
    }//GEN-LAST:event_CBmedioPagoItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(medioPagoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(medioPagoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(medioPagoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(medioPagoForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                medioPagoForm dialog = new medioPagoForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox CBmedioPago;
    private javax.swing.JTable JTmedioPago;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelAñadir;
    private javax.swing.JTextField txtMonto;
    private javax.swing.JTextField txtPrueba;
    // End of variables declaration//GEN-END:variables

   

}